package main.java.person.fjsp.algorithm.ts;

import main.java.person.fjsp.algorithm.ga.utils.GAUtils;
import main.java.person.fjsp.algorithm.ts.entity.DisjunctiveGraph;
import main.java.person.fjsp.algorithm.ts.utils.TSUtils;
import main.java.person.fjsp.common.entity.DataManager;
import main.java.person.fjsp.common.entity.ScheduleResult;
import main.java.person.fjsp.common.utils.ProcessDataUtils;

import java.io.IOException;

public class TSTest {

    public static void main(String[] args) throws IOException {
        long l = System.currentTimeMillis();


        String dataName="MK";
        String dataNumber = "01";
        String path = "D:\\郭星的文件\\研究生\\浏览器下载\\参考文献\\tradition_fjsp-master\\tradition_fjsp-master\\data\\Monaldo\\Fjsp\\Job_Data\\Barnes\\Text\\mt10c1.fjs";
        DataManager dataManager = new ProcessDataUtils().readFileToJobList(path);

        long beginTime = System.currentTimeMillis();
        TSUtils tsUtils = new TSUtils();
        ScheduleResult scheduleResult = new GAUtils().getRandomSchedule(dataManager);
        //生成该调度计划的析取图
        DisjunctiveGraph disjunctiveGraph = tsUtils.convertScheduleToGraph(scheduleResult, dataManager);

        DisjunctiveGraph solve = new TSSolver(50, 10000, 70,7000).solve(disjunctiveGraph, dataManager);
        System.out.println(solve.getMakespan());

        new ProcessDataUtils().writeSchedule("result/TS-"+dataName + dataNumber + ".txt", tsUtils.convertGraphToSchedule(solve));
        System.out.println(System.currentTimeMillis() - beginTime);


    }


    public static int binarySearch(int start, int end, int[] nums, int target) {
        if (start == end) {
            return start;
        }
        int middle = (int) Math.ceil((start + end) / 2.0);
        if (nums[middle] <= target) {
            return binarySearch(start, middle, nums, target);
        } else {
            return binarySearch(middle + 1, end, nums, target);
        }
    }
}
